/*
abstract:
    convert com interface to simple C class

    $Header: /Windows/Shell/ShellExt.root/ShellExt/src/CIShellExtImp.h 1     08-01-05 0:08 Ken $
    $Log: /Windows/Shell/ShellExt.root/ShellExt/src/CIShellExtImp.h $
 * 
 * 1     08-01-05 0:08 Ken
*/

#pragma once

#define DEF_ICON_OL_PRIORITY    30

class ATL_NO_VTABLE CIShellExtInitImp
    :public IShellExtInit
    ,public IPersistFile
{
public:
    CIShellExtInitImp(){};
    ~CIShellExtInitImp(void){};

// IShellExtInit
public:
     STDMETHOD(Initialize)(LPCITEMIDLIST, LPDATAOBJECT, HKEY);

// IPersistFile ,only Load() is needed!
public:
    STDMETHOD(GetClassID)(LPCLSID) { return E_NOTIMPL; };
    STDMETHOD(IsDirty)() { return E_NOTIMPL; };
    STDMETHOD(Load)(LPCOLESTR, DWORD);
    STDMETHOD(Save)(LPCOLESTR, BOOL) { return E_NOTIMPL; };
    STDMETHOD(SaveCompleted)(LPCOLESTR) { return E_NOTIMPL; };
    STDMETHOD(GetCurFile)(LPOLESTR*) { return E_NOTIMPL; };

// the init implement
protected:
    virtual BOOL VTgtInit(TCHAR* pszFl)=0;
    virtual BOOL VPreSrcInit(UINT uSrcNumb ){return TRUE;};
    virtual BOOL VSrcInit(UINT uSrcId, TCHAR* pszFl, BOOL fLoad=FALSE/*called by Load*/ )=0;

};


class ATL_NO_VTABLE CIShlCntxMenuImp
    :public IContextMenu
{
public:
    CIShlCntxMenuImp(){};
    ~CIShlCntxMenuImp(void){};

// IContextMenu
public:
    // get hit for command
    STDMETHOD(GetCommandString)(UINT, UINT, UINT*, LPSTR, UINT);
    STDMETHOD(QueryContextMenu)(HMENU, UINT, UINT, UINT, UINT);
    STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO);

// the context menu implement
protected:
    virtual BOOL VIsCmdValid(DWORD dwId)=0;
    virtual const TCHAR* VGetMenuString(DWORD dwId)=0;
    virtual HBITMAP VGetMenuBmp(DWORD dwId){return NULL;};
    // get hit for command
    virtual const TCHAR* VGetCmdHit(DWORD dwId){return NULL;};
    virtual BOOL VInvokeCommand(LPCMINVOKECOMMANDINFO pInfo, DWORD dwId)=0;
    virtual DWORD VGetCmdNumb()=0;
};

class ATL_NO_VTABLE CIShlIconImp
    :public IShellIconOverlayIdentifier
{
public:
    CIShlIconImp(HINSTANCE hInstance,DWORD iIndex)
    :m_iIndex(iIndex)
    {
		m_dwNameLen=GetModuleFileNameW( hInstance, m_wszIconFileName, sizeof(m_wszIconFileName)/sizeof(m_wszIconFileName[0]) );
    };

// IShellIconOverlayIdentifier
public:
    //This method is called by the Shell at startup so that the handler's icon overlay can be added to the system image list.
    STDMETHOD(GetOverlayInfo)( LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
    STDMETHOD(GetPriority)( int *pPriority ){*pPriority=DEF_ICON_OL_PRIORITY; return S_OK;};
//    STDMETHOD(IsMemberOf)( LPCWSTR pwszPath, DWORD dwAttrib ); // derived class implete

protected:
    WCHAR m_wszIconFileName[MAX_PATH];
    DWORD m_dwNameLen;
    DWORD m_iIndex;
};

template <const CLSID* T_PCLSID = &CLSID_NULL>
class ATL_NO_VTABLE CIPersistStreamStubImp
    : public IPersistStream
{
//
// shell interfaces
public:
    //IPersistStream methods
    STDMETHOD (GetClassID) (LPCLSID pClassID)
    {
        *pClassID = *T_PCLSID;
        return S_OK;
    };
    STDMETHOD (IsDirty) (void){return S_FALSE;};
    STDMETHOD (Load) (LPSTREAM){return S_OK;};
    STDMETHOD (Save) (LPSTREAM, BOOL){return S_OK;};
    STDMETHOD (GetSizeMax) (ULARGE_INTEGER*){return E_NOTIMPL;};
};


